package cn.cheln.explorer.func.setup;

import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.HandlerThread;
import android.os.Message;
import cn.cheln.explorer.beans.AppInfoData;
import cn.cheln.explorer.beans.ReportInfo;
import cn.cheln.support.images.Utillocal;
import cn.cheln.support.log.Logs;
import cn.cheln.support.notification.NotifyUtil;
import com.direction.hold.FileApp;
import com.direction.hold.ui.CommonActivity;
import com.direction.hold.ui.CountActivity;
import com.direction.hold.ui.PathActivity;
import com.direction.hold.ui.SlideActivity;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class PackageInstallManager
{
  public static final String STR_FAIL_APP_LABEL = "failureAppLabels";
  public static boolean homeStopFlag;
  private static PackageInstallManager instance;
  public static boolean isInInstall;
  public static boolean shouldStopInstall;
  public static ArrayList<String> toInstallPaths;
  String apkpath;
  public Intent backIntent;
  private Context context;
  boolean currentSuccess = false;
  int currentTextShow = -1;
  public int faliureNum = 0;
  String intallingAppLabel;
  LoaderThread loaderThread;
  NotifyUtil notifyUtil;
  List<String> paths = null;
  public InstallHelper pi;
  String recentLabel = "";
  public boolean renamedFlag = false;
  public int successNum = 0;
  public int unhandled = 0;

  protected PackageInstallManager(InstallHelper paramInstallHelper, Context paramContext)
  {
    this.pi = paramInstallHelper;
    this.context = paramContext;
    this.notifyUtil = new NotifyUtil(paramContext);
    this.backIntent = new Intent("com.lewa.filemgr.install");
    this.backIntent.addCategory("android.intent.category.DEFAULT");
  }

  public static PackageInstallManager createPackageManagerInstance(InstallHelper paramInstallHelper, Context paramContext)
  {
    if (instance == null)
      instance = new PackageInstallManager(paramInstallHelper, paramContext);
    return instance;
  }

  public static PackageInstallManager getInstance()
  {
    if (PackageInstallService.context == null);
    for (Object localObject = SlideActivity.activity; ; localObject = PackageInstallService.context)
      return getInstance((Context)localObject);
  }

  public static PackageInstallManager getInstance(Context paramContext)
  {
    if (paramContext != null);
    for (Object localObject = paramContext; (instance == null) || (paramContext != null); localObject = FileApp.activity)
      return createPackageManagerInstance(new InstallHelper((Context)localObject), (Context)localObject);
    return ((PackageInstallManager)instance);
  }

  public static void notifyAllInstalled(NotifyUtil paramNotifyUtil, int paramInt, Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4, Context paramContext, Intent paramIntent)
  {
    Logs.i("-----------" + paramInteger1 + " " + paramInteger2 + " " + paramInteger4);
    String str1 = paramContext.getString(2131034220) + " " + paramInteger1 + " ";
    String str2 = paramContext.getString(2131034221) + " " + paramInteger2 + " ";
    String str3 = paramContext.getString(2131034222) + " " + paramInteger3 + " ";
    String str4 = paramContext.getString(2131034223) + " " + paramInteger4;
    String str5 = paramContext.getString(paramInt);
    String str6 = str1 + " " + str2 + " " + str3 + " " + str4;
    String str7 = paramContext.getString(paramInt);
    NotifyUtil.cancel(paramContext, 0);
    notifyInstallId(paramNotifyUtil, str7 + "  " + str1 + str2 + str3 + str4, str5, str6, paramIntent, FileApp.activity, BroadcastReceiver.class);
  }

  private static void notifyInstallId(NotifyUtil paramNotifyUtil, String paramString1, String paramString2, String paramString3, Intent paramIntent, Context paramContext, Class paramClass)
  {
    paramNotifyUtil.notify(0, 2130837514, paramString1, paramString2, paramString3, paramIntent, paramContext, paramClass);
  }

  private void popInstallReport()
  {
    int i = SlideActivity.paramActivity.currFrameId;
    if (i == 0);
    for (Object localObject = CountActivity.categoryActivity; ; localObject = PathActivity.activityInstance)
      do
      {
        ((CommonActivity)localObject).handler.sendEmptyMessage(14);
        return;
        localObject = null;
      }
      while (i != 1);
  }

  private void tellPreviousInstallationDone(NotifyUtil paramNotifyUtil, String paramString1, String paramString2, int paramInt, boolean paramBoolean, Integer paramInteger1, Integer paramInteger2)
  {
    String str1 = paramString2 + " " + this.context.getString(paramInt);
    String str2 = this.context.getApplicationContext().getString(2131034219) + " [" + paramString1 + "] " + constructProgress(paramInteger1.intValue(), paramInteger2.intValue());
    StringBuilder localStringBuilder = new StringBuilder(String.valueOf(paramString2)).append(" ");
    if (paramBoolean);
    for (String str3 = this.context.getString(2131034224); ; str3 = "")
    {
      notifyInstallId(paramNotifyUtil, str1, str2, str3 + this.context.getString(paramInt), this.backIntent, FileApp.activity, Activity.class);
      return;
    }
  }

  public void beginAllInstall(NotifyUtil paramNotifyUtil, Integer paramInteger, String paramString, Context paramContext)
  {
    notifyInstallId(paramNotifyUtil, paramContext.getString(2131034213), paramContext.getString(2131034219) + " [" + paramString + "] " + constructProgress(1, paramInteger.intValue()), paramContext.getString(2131034215), this.backIntent, paramContext, Service.class);
  }

  public void beginInstall(List<String> paramList)
  {
    getInstance().clearHistory();
    getInstance().clear();
    this.loaderThread = new LoaderThread(this);
    this.loaderThread.start();
    isInInstall = true;
    this.unhandled = paramList.size();
    this.paths = paramList;
    String str1 = this.pi.getIteratorNext(paramList);
    this.intallingAppLabel = getApkLabel(str1);
    if ((this.intallingAppLabel == null) || (this.intallingAppLabel.equals(new File(str1).getName())));
    for (String str2 = this.context.getString(2131034239); ; str2 = this.intallingAppLabel)
    {
      this.intallingAppLabel = str2;
      Message localMessage = new Message();
      localMessage.what = 0;
      localMessage.obj = str1;
      this.loaderThread.requestLoading(localMessage);
      return;
    }
  }

  public void clear()
  {
    this.faliureNum = 0;
    this.successNum = 0;
    this.unhandled = 0;
  }

  public void clearHistory()
  {
    ReportOfInstall.clear();
  }

  public String constructProgress(int paramInt1, int paramInt2)
  {
    return " (" + paramInt1 + "/" + paramInt2 + ") ";
  }

  public void end(Integer paramInteger)
  {
    notifyOverResult(paramInteger.intValue());
    clear();
    NotifyUtil.cancel(FileApp.activity, 0);
    isInInstall = false;
  }

  public void endWhileAppAlive()
  {
    ReportOfInstall.prepareReportText(this.context);
    popInstallReport();
    notifyAllInstalled(this.notifyUtil, 2131034218, Integer.valueOf(this.successNum), Integer.valueOf(this.faliureNum), Integer.valueOf(this.unhandled), this.pi.getTotalInstallSum(), this.context, this.backIntent);
    isInInstall = false;
  }

  public String getApkLabel(String paramString)
  {
    if (paramString == null)
      return null;
    File localFile = new File(paramString);
    AppInfoData localAppInfoData = Utillocal.getApkInfo(this.context, localFile);
    if (localAppInfoData == null)
      return localFile.getName();
    return localAppInfoData.name;
  }

  public void notifyOverResult()
  {
    notifyOverResult(2131034218);
  }

  public void notifyOverResult(int paramInt)
  {
    Intent localIntent;
    if (paramInt == 2131034291)
    {
      localIntent = new Intent("com.lewa.filemgr.install");
      localIntent.addCategory("android.intent.category.DEFAULT");
    }
    while (true)
    {
      notifyAllInstalled(this.notifyUtil, paramInt, Integer.valueOf(this.successNum), Integer.valueOf(this.faliureNum), Integer.valueOf(this.unhandled), this.pi.getTotalInstallSum(), this.context, localIntent);
      return;
      FileApp localFileApp = FileApp.activity;
      localIntent = null;
      if (localFileApp != null)
        localIntent = new Intent("com.lewa.filemgr.install");
      localIntent.addCategory("android.intent.category.DEFAULT");
    }
  }

  public void packageInstalled(String paramString1, int paramInt, boolean paramBoolean, String paramString2)
  {
    int i;
    int j;
    if (homeStopFlag);
    do
    {
      return;
      if (shouldStopInstall)
      {
        shouldStopInstall = false;
        return;
      }
      Logs.i("failureAppLabels ---- packageInstalled " + paramString1 + " " + paramInt);
    }
    while (this.pi.getCurrInstallPath() == null);
    if (!(paramBoolean))
    {
      this.successNum = (1 + this.successNum);
      this.unhandled = (-1 + this.unhandled);
      ReportOfInstall.success.add(new ReportInfo(this.apkpath, paramString2));
    }
    if (!(paramBoolean))
    {
      i = 2131034216;
      label112: Logs.i("", "finishedAllInstall ---- apkpath " + this.apkpath);
      j = 0;
      if (!(paramBoolean))
        break label189;
    }
    while (true)
    {
      this.currentSuccess = j;
      this.currentTextShow = i;
      this.recentLabel = paramString2;
      Logs.e("=== startService PackageInstallService");
      if (tryNextInstall(paramString2, i, paramBoolean));
      return;
      i = 2131034217;
      break label112:
      label189: j = 1;
    }
  }

  public boolean tryNextInstall(String paramString, int paramInt, boolean paramBoolean)
  {
    this.apkpath = this.pi.getIteratorNext(this.pi.getPaths());
    Logs.i("", "finishedAllInstall ---- apkpath " + this.apkpath);
    if (!(this.pi.hasNext(this.apkpath)))
    {
      endWhileAppAlive();
      return false;
    }
    String str = getApkLabel(this.apkpath);
    NotifyUtil localNotifyUtil = this.notifyUtil;
    if (paramBoolean);
    for (boolean bool = false; ; bool = true)
    {
      tellPreviousInstallationDone(localNotifyUtil, str, paramString, paramInt, bool, Integer.valueOf(this.pi.getCurrInstallIdx()), this.pi.getTotalInstallSum());
      this.pi.tryInstall(this.apkpath);
      return false;
    }
  }

  public static class LoaderThread extends HandlerThread
    implements Handler.Callback
  {
    private final PackageInstallManager installManager;
    private Handler mLoaderThreadHandler;

    public LoaderThread(PackageInstallManager paramPackageInstallManager)
    {
      super("");
      this.installManager = paramPackageInstallManager;
    }

    public boolean handleMessage(Message paramMessage)
    {
      switch (paramMessage.what)
      {
      default:
      case 0:
      case 1:
      }
      while (true)
      {
        return false;
        String str = paramMessage.obj.toString();
        if (!(this.installManager.pi.hasNext(str)))
          continue;
        this.installManager.pi.tryInstall(str);
        Message localMessage = new Message();
        localMessage.what = 1;
        requestLoading(localMessage);
        continue;
        this.installManager.tryNextInstall(this.installManager.recentLabel, this.installManager.currentTextShow, this.installManager.currentSuccess);
      }
    }

    public void requestLoading(Message paramMessage)
    {
      if (this.mLoaderThreadHandler == null)
        this.mLoaderThreadHandler = new Handler(getLooper(), this);
      this.mLoaderThreadHandler.sendMessage(paramMessage);
    }
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.explorer.func.setup.PackageInstallManager
 * JD-Core Version:    0.5.2
 */